package org.myself.meeting.controller;

import org.myself.meeting.Utils.Constant;
import org.myself.meeting.model.Base;
import org.myself.meeting.model.Employee;
import org.myself.meeting.model.Result;
import org.myself.meeting.model.SignIn;
import org.myself.meeting.service.AbsenceService;
import org.myself.meeting.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
public class HeadManController {

    @Autowired
    EmployeeService employeeService;

    @Autowired
    AbsenceService absenceService;



    @RequestMapping("/checkwork")
    @ResponseBody
    public Result checkWork(@RequestBody Base base){
        Employee emp =employeeService.getEmpsByUsername(base.getUsername()) ;
        if(emp.getRole() != Constant.TWOROlE){
            return new Result(400,"错误,禁止访问",null);
        }
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("adsence",absenceService.getAllAbsence());
        map.put("employee",employeeService.getEmpsByDepRole(emp.getDepartmentid()));
        return new Result(200,"成功",map);
    }
    @RequestMapping("/checkworkget")
    @ResponseBody
    public Result checkWorkGet(@RequestBody SignIn signIn){
        signIn.setThetime(new Date());
        Integer result = absenceService.addSignIn(signIn);
        if(result == 1){
            return new Result(200,"成功",null);
        }
        return new Result(400,"失败",null);

    }
}
